home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1997 August / Walnut Creek CDROM.7z / VOL_400 / 460_01 / YACL0160.ZIP / uidemo / bitmap0 / main.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-29  |  3.9 KB  |  118 lines

  1.  
  2.  
  3. // This is a simple bitmap demo program using YACL. It illustrates how the
  4. // application can put together a bitmap without using any resources, and
  5. // have it displayed.
  6. //
  7. // M. A. Sridhar
  8. // August 3, 1995
  9.  
  10. #include "ui/composit.h"
  11. #include "ui/bitmap.h"
  12. #include "ui/dsplsurf.h"
  13. #include "ui/applic.h"
  14.  
  15.  
  16. // ======================== Class AppWindow ===========================
  17.  
  18. class AppWindow: public UI_CompositeVObject {
  19.  
  20. public:
  21.     AppWindow ();
  22.     ~AppWindow ();
  23.     
  24.     // Override the Composite's virtual method:
  25.     void Initialize ();
  26.  
  27.     bool Paint (const UI_Rectangle&);
  28.  
  29. protected:
  30.     UI_BitmapData _bmpData;
  31.     UI_Bitmap     _bitmap;
  32. };
  33.  
  34. UI_BitmapData::ColorInfo colors[256] = {
  35. {000, 180, 000},
  36. {230, 230, 230},
  37. {000, 000, 255},
  38. {255,   0,   0},
  39. {0, 0, 0}
  40. };
  41.  
  42. ulong pixels [] = {
  43.  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  44.  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  45.  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  46.  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  47.  1, 1, 1, 1, 2,  2, 2, 2, 2, 2,  2, 2, 2, 2, 2,  2, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  48.                                                                                
  49.  1, 1, 1, 1, 1,  2, 2, 2, 2, 2,  2, 2, 2, 2, 2,  1, 3, 3, 3, 3,  3, 3, 3, 1, 1,
  50.  1, 1, 1, 1, 1,  2, 2, 2, 2, 2,  2, 2, 2, 2, 1,  1, 1, 3, 3, 3,  3, 3, 3, 1, 1,
  51.  1, 1, 1, 1, 1,  2, 2, 2, 2, 2,  2, 2, 2, 1, 1,  1, 1, 3, 3, 3,  3, 3, 3, 1, 1,
  52.  1, 1, 1, 1, 1,  2, 2, 2, 2, 2,  2, 2, 1, 1, 1,  1, 1, 1, 3, 3,  3, 3, 3, 1, 1,
  53.  1, 1, 1, 1, 1,  2, 2, 2, 2, 2,  2, 1, 1, 1, 1,  1, 1, 1, 1, 3,  3, 3, 3, 1, 1,
  54.                                                                                
  55.  1, 1, 1, 1, 1,  2, 2, 2, 2, 2,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  3, 3, 3, 1, 1,
  56.  1, 1, 1, 1, 1,  2, 2, 2, 2, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 3, 3, 1, 1,
  57.  1, 1, 1, 1, 1,  2, 2, 2, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 3, 1, 1,
  58.  1, 1, 1, 1, 1,  2, 2, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  59.  1, 1, 1, 1, 1,  2, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  60.                                                                                
  61.  1, 1, 1, 1, 1,  0, 0, 0, 0, 0,  0, 0, 0, 0, 0,  0, 0, 0, 0, 0,  1, 1, 1, 1, 1,
  62.  1, 1, 1, 1, 1,  1, 0, 0, 0, 0,  0, 0, 0, 0, 0,  0, 0, 0, 0, 1,  1, 1, 1, 1, 1,
  63.  1, 1, 1, 1, 1,  1, 1, 0, 0, 0,  0, 0, 0, 0, 0,  0, 0, 0, 1, 1,  1, 1, 1, 1, 1,
  64.  1, 1, 1, 1, 1,  1, 1, 1, 0, 0,  0, 0, 0, 0, 0,  0, 0, 1, 1, 1,  1, 1, 1, 1, 1,
  65.  1, 1, 1, 1, 1,  1, 1, 1, 1, 0,  0, 0, 0, 0, 0,  0, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  66.     
  67.  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  0, 0, 0, 0, 0,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  68.  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 0, 0, 0, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  69.  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 0, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  70.  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,
  71.  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1,  1, 1, 1, 1, 1
  72.  
  73. };
  74. AppWindow::AppWindow()
  75. : UI_CompositeVObject (NULL, NULL, FALSE, UI_Rectangle (40, 40, 100, 100)),
  76.   _bmpData (25, 25, UI_BitmapData::Color_8Bits, 5, colors, pixels)
  77. {
  78.     _title = "YACL Bitmap Demo";
  79. }
  80.  
  81.  
  82. void AppWindow::Initialize ()
  83. {
  84.     CreateDisplaySurface ();
  85.     _bitmap.BuildFrom (_bmpData);
  86. }
  87.  
  88. bool AppWindow::Paint (const UI_Rectangle&)
  89. {
  90.     _displaySurface->ColorRectangle (_displaySurface->DrawingArea(),
  91.                                      UIColor_White);
  92.     _bitmap.DrawOn (*_displaySurface, UI_Point (38, 38));
  93.     return FALSE; // Return FALSE, as a rule, so that event dependents (if
  94.                   // any) can be notified
  95. }
  96.  
  97.  
  98.  
  99. AppWindow::~AppWindow ()
  100. {
  101.     DestroyDisplaySurface ();
  102. }
  103.  
  104.  
  105.  
  106.  
  107. // ========================== Main program ==========================
  108.  
  109.  
  110. int UI_Application::Main (int, char* [])
  111. {
  112.     MakeTopWindow (new AppWindow);
  113.     Run();
  114.     return 0;
  115. }
  116.  
  117.  
  118.